
var api = require('../../../../utils/api.js');
const app = getApp();
Page({

  data: {

    data: [],

    curr: "",
    imgUrl: app.globalData.imgUrl,
    name:'',
    id:'',
    login:false

  },

  /*点击切换页面*/

  onLoad: function (options) {
    var id = options.id;
    var name = options.name;
    this.setData({
      id:id,
      name:name
    })
    wx.setNavigationBarTitle({
      title: name
    });

    var is_login = wx.getStorageSync('login');
    if(is_login){
      this.setData({
        login:true
      })
    }
    this.getimg(id);

  },

  getimg: function (id) {
    var that = this;
    api.post({
      url: 'festival/Index/showView',
      data: { id: id },
      success: res => {
        console.log(res);
        that.setData({
          data: res.data
        })
      }
    })
  },

  ondashang:function(){
    wx.navigateTo({
      url: '../../../areward/areward',
    });
  },

  getuserinfo: function (e) {
    var that = this;
    console.log(e);
    var res = e.detail;
    wx.setStorageSync('userInfo', res.userInfo);
    if (res.encryptedData) {
      wx.login({
        success: loginRes => {
          if (loginRes.code) {
            api.post({
              url: 'wxapp/szufu/login',
              data: {
                code: loginRes.code,
                encrypted_data: res.encryptedData,
                iv: res.iv,
                raw_data: res.rawData,
                signature: res.signature
              },
              success: data => {
                console.log(data);
                if (data.code == 1) {
                  // wx.showToast({
                  //   title: '登录成功!',
                  //   icon: 'success',
                  //   duration: 1000
                  // });
                  try {
                    wx.setStorageSync('login', '1');
                    wx.setStorageSync('token', data.data.token);
                    wx.setStorageSync('user', data.data.user);
                    wx.setStorageSync('ooid', data.data.openid);
                  } catch (e) {
                  }
                  that.setData({
                    login: true
                  })

                  that.ondashang();
                }
              }
            })
          }
        }
      })
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    var name = this.data.name;
    var id = this.data.id;
    return {
      title: name,
      desc: '大家都在送祝福，你也来给朋友送祝福吧!',
      path: '/pages/index/child/view/view?id='+id+'&name='+name
    }
  }

})

